{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "96ab2cbb-3ecd-47aa-b117-1c28e1815149",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "class Dog():\n",
    "    def info(self):\n",
    "        print(\"这是一只%s\" %self.name)\n",
    "    def HP(self):\n",
    "        print(\"他的生命值为%d\" %self.hp)\n",
    "Jinmao = Dog()\n",
    "Jinmao.name = \"金毛\"\n",
    "Jinmao.hp = 100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "992e7a82-d05e-42e6-9b8d-74cf0ecbffa6",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "这是一只金毛\n"
     ]
    }
   ],
   "source": [
    "Jinmao.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "260c6eb0-4f49-4b6e-a9fa-6c1ff30edadb",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "他的生命值为100\n"
     ]
    }
   ],
   "source": [
    "Jinmao.HP()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "f6195a54-582b-482b-b4a9-451afc02379f",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "金毛的生命值为100,金毛的攻击力为200\n"
     ]
    }
   ],
   "source": [
    "class Dog():\n",
    "    def __init__(self):\n",
    "        self.name = \"金毛\"\n",
    "        self.hp = 100\n",
    "        self.attack = 200\n",
    "    def info(self):\n",
    "        print(\"%s的生命值为%d,%s的攻击力为%d\"%(self.name,self.hp,self.name,self.attack))\n",
    "class son(Dog):\n",
    "    pass\n",
    "JImao = son()\n",
    "JImao.info()\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "a9a6874f-0359-4bf0-a079-31f7e935c3e9",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'金毛'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Jimao.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "4ec37f08-5886-4345-acbd-444ce8dba9a2",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<__main__.Dog object at 0x0000024419C68340>\n",
      "狗祖宗\n",
      "<__main__.Dog object at 0x0000024419C68340>\n",
      "2491513471808\n"
     ]
    }
   ],
   "source": [
    "class Dog():\n",
    "    def info(self):\n",
    "        print(self)\n",
    "        print(\"狗祖宗\")\n",
    "jinmao = Dog()\n",
    "jinmao.info()\n",
    "print(jinmao)\n",
    "print(id(jinmao))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "6df5dcfb-281e-4783-a9f6-e608d0e4c589",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小菜的生命值为2600\n",
      "正在前往事发地点\n",
      "咬人\n"
     ]
    }
   ],
   "source": [
    "class Dog():\n",
    "    def move(self):\n",
    "        print(\"正在前往事发地点\")\n",
    "    def attack(self):\n",
    "        print(\"咬人\")\n",
    "jinmao = Dog()\n",
    "jinmao.name = \"小菜\"\n",
    "jinmao.hp = 2600\n",
    "jinmao.atk =450\n",
    "jinmao.armor = 200 #护甲值\n",
    "print(\"%s的生命值为%d\"%(jinmao.name,jinmao.hp))\n",
    "jinmao.move()\n",
    "jinmao.attack()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "06f431c2-91f0-42a6-80b5-d374886c3846",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小菜的生命值为100\n",
      "小菜的攻击力为1000\n"
     ]
    }
   ],
   "source": [
    "class Dog():\n",
    "    def move(self):\n",
    "        print(\"正在前往事发地点\")\n",
    "    def attack(self):\n",
    "        print(\"咬人\")\n",
    "    def info(self):\n",
    "        print(\"%s的生命值为%d\"%(self.name,self.hp))\n",
    "        print(\"%s的攻击力为%d\"%(self.name,self.atk))\n",
    "jinmao = Dog()\n",
    "jinmao.name = \"小菜\"\n",
    "jinmao.hp =100\n",
    "jinmao.atk = 1000\n",
    "jinmao.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "563abb4b-6473-4142-ae21-c6932a6df028",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小菜的生命值为100\n",
      "小菜的攻击力为1000\n",
      "正在前往事发地点\n"
     ]
    }
   ],
   "source": [
    "class Dog():\n",
    "    def __init__(self):\n",
    "        self.name =\"小菜\"\n",
    "        self.hp = 100\n",
    "        self.atk =1000\n",
    "    def move(self):\n",
    "        print(\"正在前往事发地点\")\n",
    "    def attack(self):\n",
    "        print(\"咬人\")\n",
    "    def info(self):\n",
    "        print(\"%s的生命值为%d\"%(self.name,self.hp))\n",
    "        print(\"%s的攻击力为%d\"%(self.name,self.atk))\n",
    "jinmao = Dog()\n",
    "\n",
    "jinmao.info()\n",
    "jinmao.move()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "d7c432e3-66e8-4bf9-ac03-bc2e359410bd",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "__init__方法被调用 小菜狗出生了\n",
      "__del__方法被调用小菜狗死了\n",
      "__init__方法被调用 小傻狗出生了\n",
      "__del__方法被调用小傻狗死了\n",
      "小菜狗咬小傻狗\n",
      "程序结束\n",
      "\n",
      "__del__方法被调用小菜狗死了\n"
     ]
    }
   ],
   "source": [
    "class Dog():\n",
    "    def __init__(self,name):\n",
    "        print(\"__init__方法被调用\",name+\"出生了\")\n",
    "        self.name = name\n",
    "    #当对象被删除时自动调用\n",
    "    def __del__(self):\n",
    "        print(\"__del__方法被调用%s死了\"%self.name)\n",
    "    def attack(self,name):\n",
    "        print(self.name+\"咬\"+name)\n",
    "jinmao = Dog('小菜狗')\n",
    "hashiqi = Dog(\"小傻狗\")\n",
    "jinmao.attack(\"小傻狗\")\n",
    "print(\"程序结束\\n\")\n",
    "jinmao=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f55ab359-f459-4b82-93e2-51f5630c3968",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dog son\n",
      "lick people\n",
      "摇尾巴\n",
      "attack peopel\n"
     ]
    }
   ],
   "source": [
    "class Dog():\n",
    "    def __init__(self):\n",
    "        self.name = \"dog_dad\"\n",
    "    def skill3(self):\n",
    "        print('attack peopel')\n",
    "class Dog2():\n",
    "    def __init__(self):\n",
    "        self.name = 'dog mom'\n",
    "    def skill(self):\n",
    "        print('attack dog')\n",
    "    def skill2(self):\n",
    "        print('摇尾巴')\n",
    "class son(Dog,Dog2):\n",
    "    def __init__(self):\n",
    "        self.name ='dog son'\n",
    "        \n",
    "    def skill(self):\n",
    "        print('lick people')\n",
    "jinmao =son()\n",
    "print(jinmao.name)\n",
    "jinmao.skill()\n",
    "jinmao.skill2()\n",
    "jinmao.skill3()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "c8e534d6-24f8-47a1-ac20-a19059bc39d3",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lick people\n",
      "attack people\n",
      "attack dog\n",
      "摇尾巴\n",
      "dog son\n"
     ]
    }
   ],
   "source": [
    "class Dog():\n",
    "    def __init(self):\n",
    "        self.name ='dog dad'\n",
    "    def skill(self):\n",
    "        print('attack people')\n",
    "class Dog2():\n",
    "    def __init__(self):\n",
    "        self.name = 'dog mom'\n",
    "    def skill(self):\n",
    "        print('attack dog')\n",
    "    def skill2(self):\n",
    "        print('摇尾巴')\n",
    "class son(Dog,Dog2):\n",
    "    def __init__(self):\n",
    "        self.name = \"dog son\"\n",
    "    def skill(self):\n",
    "        print('lick people')\n",
    "    def dad_skill(self):\n",
    "        Dog.skill(self)\n",
    "        Dog.__init__(self)\n",
    "       \n",
    "    def mom_skill(self):\n",
    "        #Dog2.__init__(self)\n",
    "        Dog2.skill(self)\n",
    "        Dog2.skill2(self)\n",
    "       \n",
    "jinmao = son()\n",
    "jinmao.skill()\n",
    "jinmao.dad_skill()\n",
    "jinmao.mom_skill()\n",
    "print(jinmao.name)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1ee31d5-97e1-40ae-a374-ab97cd71fbc2",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}